package com.sikaryofficial.qrcode.service.impl;

import com.anwen.mongo.service.impl.ServiceImpl;
import com.sikaryofficial.qrcode.domain.mongo.QrUserDetailMongo;
import com.sikaryofficial.qrcode.service.QrUserDetailMongoService;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

/**
 * @author : qinjinyuan
 * @desc : TODO  请填写你的功能描述
 * @date : 2024/11/13 17:43
 */
@Service
@Slf4j
public class QrUserDetailMongoServiceImpl extends ServiceImpl<QrUserDetailMongo> implements QrUserDetailMongoService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public long countDocument() {
        // 执行 MongoDB 命令获取集合的统计信息
        try {
            Document command = new Document("collStats", "qr_user_detail_t");
            Document result = mongoTemplate.executeCommand(command);
            Integer count = result.getInteger("count");
            return count != null ? count.longValue() : 0L;
        } catch (Exception e) {
            log.error("countDocument error:{}", e);
            // 根据实际需求处理异常或记录日志
            return 0L;
        }
    }
}
